package mysql

import "web_app/modules"

func CreatePost(p *modules.Post) error {

	result := GormDB.Create(&p)

	if result.Error != nil {
		return result.Error
	}

	if result.RowsAffected > 0 {
		return nil
	} else {
		return ErrorInsertUser
	}
	return nil
}

func FindPostByID(postID int64) (*modules.Post, error) {
	post := modules.Post{}
	result := GormDB.Where("post_id = ?", postID).Find(&post)
	if result.Error != nil {
		return nil, result.Error
	}

	if result.RowsAffected == 0 {
		return nil, ErrorDataNotExist
	}
	return &post, nil

}
